/**
 * @created by zhangpeng18 on 2019-8-5 10:40:22
 * @updated by
 * @description Java类驱动管理
 */
define(
	['./libs/ace-editor/index.js'],
	function(require, exports) {
		/**
		 * 页面加载完成时触发
		 * @param hashCode 路由ID
		 * @param data 传递数据对象
		 * @param cite 页面站点信息
		 */
		exports.ready = function(hashCode, data, cite) {
			yufp.custom.vue({
				el: cite.el,
				data: function() {

					var paramTypeOption = [{
							key: 'C',
							value: '常量'
						},
						{
							key: 'Q',
							value: 'SQL查询'
						}
					]

					var _this = this;
					/*定义校验规则，只能填字母数字 下划线*/
					var valiCodes = function(rule, value, callback) {
						var reg = /^[0-9a-zA-Z_]{1,}$/;
						if (value && reg.test(value)) {
							if (value.length > 64) {
								callback(new Error('长度不能大于64位'));
							} else {
								callback();
							}
						} else if (value && !reg.test(value)) {
							callback(new Error('能填字母、数字和下划线'));
						} else {
							callback();
						}
					};
					/**检验数字大于0*/
					var numMax = function(rule, value, callback) {
						if (value) {
							if (Number(value) <= 0) {
								callback(new Error('数字必须大于0'));
							} else {
								callback();
							}
						} else {
							callback();
						}
					};
					/**检验字段长度小于定义的长度*/
					/* 			var defineLen = function (rule, value, callback) {
									 debugger
									 var dlen = this.formdata.paramSize;
									callback();
								}; */
					return {
						//校验参数代码只能为数字字母下划线
						rules: {
							classCode: [{
								validator: valiCodes,
								trigger: 'blur'
							}]
						},
						ruleslist: {
							paramCode: [{
								validator: valiCodes,
								trigger: 'blur'
							}],
							paramSize: [{
									message: '请输入数字',
									validator: yufp.validator.number
								},
								{
									validator: numMax,
									trigger: 'blur'
								}
							]
						},
						tbHeight:'0',
						upLoadDialogVisible:false,//是否显示导入页面
						upLoadUrl: yufp.service.getUrl({ url: "api/file/provider/uploadfile" }),//导入的url
						appUploadDatas: [],//文件列表
						showHeader:false,//是否显示错误表头
						errshow:false,//显示导入的错误信息，默认不显示
						excelloading:false,//导入的loading
						errdata:[],//导入的错误信息
						searchFormdata: {},
						multipleFalg:false,//是否允许多文件
						appNameDisabled: false,
						classNameDisabled: false,
						addFnButton: !yufp.session.checkCtrl('addFn'),
						updateFnButton: !yufp.session.checkCtrl('updateFn'),
						deleteFnButton: !yufp.session.checkCtrl('deleteFn'),

						addClassFnButton: !yufp.session.checkCtrl('addClassFn'),
						updateClassFnButton: !yufp.session.checkCtrl('updateClassFn'),
						deleteClassFnButton: !yufp.session.checkCtrl('deleteClassFn'),
						importFnButton: !yufp.session.checkCtrl('importFn'),
						exportFnButton: !yufp.session.checkCtrl('exportFn'),

						treeDataUrl: "api/use/plats/paramclass/queryList",
						dataUrl: 'api/use/plats/paramValue/queryList',
						saveBtnShow: true,
						cancelBtnShow: true,
						addBtnShow: false,
						formdata: {
							sqlexpression: ''
						},
						async: false,
						height: yufp.frame.size().height -147,
						dialogVisible: false,
						formDisabled: false,
						classCodeDisabled: false,
						viewTitleArrry: ['参数值增加', '参数值修改', '参数值查看'],
						viewTitle: '',
						propTabaleData: [],
						appCodeShow: true,
						appShowName: "",
						nodeData: '', // 在新增表格数据时需要先获取当前树节点，再把一条新的记录加到这个节点下的表格里,
						nodeLeaf: false,
						isDisabledAppName: false,
						isReadOnly: false,
						isViewFlag: false,
						isAppNode: false,
						isNodeLeaf: false,
						nodeLeafData: {},
						dataSources: [],
						paramOption: paramTypeOption,
						isClassaddFlag: false,
						classCodeReadOnly: false,
						sqlQuery: false,
						currAppNode: {},
						classFormdata: {},
						viewClassTitle: "",
						//isViewFlag: false,
						showAppName: true,
						showClassName: true,
						viewClassTitleArrry: ['参数类型新增', '参数类型修改'],
						classDialogVisible: false,
						classFields: [{
							columnCount: 2,
							fields: [{
									field: 'appCode',
									label: '应用系统编号:',
									disabled: true
								},
								{
									field: 'appName',
									label: '应用系统名称:',
									disabled: true
								},
								{
									field: 'classCode',
									label: '参数分类代码:',
									disabled: _this.classCodeReadOnly,
									rules: [{
											required: true,
											message: '必填项',
											trigger: 'blur'
										},
										{
											max: 64,
											message: '输入值过长',
											trigger: 'blur'
										}
									]

								},
								{
									field: 'className',
									label: '参数分类名称:',
									rules: [{
											required: true,
											message: '必填项',
											trigger: 'blur'
										},
										{
											max: 64,
											message: '输入值过长',
											trigger: 'blur'
										}
									]
								}

							]

						}, {
							columnCount: 1,
							fields: [{
								field: 'remark',
								label: '备注:',
								type: "textarea",
								rows: 3,
								rules: [{
									max: 256,
									message: '输入值过长',
									trigger: 'blur'
								}]
							}]
						}],

						classButtons: [{
								label: '取消',
								hidden: false,
								click: function(model) {
									_this.cancelClassFn();
								}
							},
							{
								label: '保存',
								type: 'primary',
								hidden: false,
								op: 'submit',
								click: function(model, valid) {
									_this.saveClassCodeFn();
								}
							}
						],

						queryName: "",
						//isReadOnly: false,
						nodeTemp: {},
						exportLoading: false
					};
				},
				mounted:function(){
					var _this = this;
					//测试
					_this.$nextTick(function(){
							var tableBox = _this.$refs.tableBox;
							let a = tableBox.getBoundingClientRect().top + 28;
							var theight = `calc(100vh - ${a}px - 64px)`;
							_this.tbHeight = theight;		
					});
				},
				methods: {
					//点击导出模板操作
					exportDemo: function(){
						var _this = this;
						var condition = {busiType:"PARAM"};
						var search = _this.searchFormdata;
						 yufp.util.download("api/use/excel/exportTempExcel?condition="
						  +  encodeURI(JSON.stringify(condition)));
					},
					//点击导出操作
					exportFlowFn: function() {
						var _this = this;






						var condition = {busiType:"PARAM"};
						var search = _this.searchFormdata;
						condition.appName = search.appName;
						condition.className = search.className;
						condition.paramName = search.paramName;

						 var selectParams = _this.$refs.refTable.selections;
						if(selectParams.length>0){
                        		 condition.paramList = [];
                        		 for(var i=0;i<selectParams.length;i++){
                                          var param = {};
                                      param.appCode = selectParams[i].appCode;
                                      param.classCode = selectParams[i].classCode;
                                      param.paramCode = selectParams[i].paramCode;
                                       condition.paramList.push(param);
                        		 }
                        		}
						_this.exportLoading = true;
						yufp.service.request({
							method: 'POST',
							url: '/api/use/excel/exportExcelForWeb',
							data: {condition: condition},
							callback: function (code, message, response) {
							  _this.exportLoading = false;
							  if (response.code === 0) {
								yufp.util.download("api/use/excel/downLoadExcel?filePath=" + response.data.allFilePath + "&fileName=" + response.data.fileName);
							  } else {
								this.$message.error('导出失败');
							  }
							}
						});
					},
					importFlowFn: function() { //点击导入操作
						this.upLoadDialogVisible = true;
						this.$nextTick(function() {
							this.$refs['my-upload'].clearFiles();
							this.errshow = false;
							this.errdata = [];
						})
					},
					/**
					 *导入前的检验操作操作
					 */
					checkUpload: function(file) {
						//alert(file);

						var isLt10M = file.size / 1024 / 1024 < 100;
						if (!isLt10M) {
							this.$message.error('上传文件大小不能超过 100MB!');
						}
						var index = file.name.lastIndexOf('.');
						var ext = file.name.substr(index + 1);

						var suffixValid = ('xlsx' === ext || 'xls' === ext);
						if (!suffixValid) {
							this.$message.error('上传文件的格式必须为excel格式');
							return false;
						}
						return isLt10M && suffixValid;
					},
					successUpload: function(response, file, fileList) { //导入成功后执行
						/*	console.log('上传成功！')
							this.$refs['my-upload'].clearFiles();*/


						const _this = this;
						const param = {};
						/* 					_this.$loading({
												target:'.load-target',
												body:true
											}) */
						_this.excelloading = true;
						param.busiType = "PARAM";
						param.excelUpLoadFile = response.data;
						yufp.service.request({
							method: 'POST',
							url: '/api/use/excel/importExcel',
							data: param,
							timeout: 1800000,
							callback: function(code, message, response) {
								_this.excelloading = false;
								if (response.code == 0 && response.data.errorInfos.length == 0 && response.data.impStatus != '失败') {
									_this.$refs['my-upload'].clearFiles();
									_this.errshow = false;
									_this.errdata = [];
									_this.upLoadDialogVisible = false;
									_this.$message('导入成功!');
									//同时重新查询列表

									var param = {
										condition: JSON.stringify(_this.searchFormdata)
									};
									_this.$refs.refTable.remoteData(param);

								} else {
									_this.errshow = true;
									_this.$refs['my-upload'].clearFiles();
									_this.errdata = [];
									if (response.data && response.data.errorInfos.length > 0 && response.data.errorInfos[0].errorList) {
										response.data.errorInfos[0].errorList.map(function(item, index) {
											_this.errdata.push({
												"errMsg": item
											})
											console.log('errdata', _this.errdata)
										})
									} else {
										_this.errdata.push({
											"errMsg": response.message
										})
									}

								}
							}
						});
					},
					//校验sql的方式只能为select，即遇到：drop，create，delete，update，insert
					validateSql: function(val) {

						var noPass = ['drop', 'create', 'delete', 'update', 'insert'];
						var flag = true;
						if (val) {
							noPass.forEach(function(item) {
								if (val.indexOf(item) != -1) {
									flag = false;
								}
							})
						}
						return flag;
					},
					onchange(code) {
						this.formdata.sqlexpression = code;
					},

					createTreeFn: function() {
						var _this = this;
						if (!_this.isAppNode) {
							_this.$message("请选择一个应用系统");
							return;
						}
						_this.classDialogVisible = true;
						_this.viewClassTitle = _this.viewClassTitleArrry[0];
						_this.isClassaddFlag = true;
						_this.classCodeReadOnly = false;
						_this.isViewFlag = false;


						_this.$nextTick(function() {
							_this.classFormdata.appCode = _this.currAppNode.appCode;
							_this.classFormdata.appName = _this.currAppNode.appName;
							_this.classFormdata.classCode = ""
							_this.classFormdata.className = ""
							_this.classFormdata.remark = ""
						});

					},
					cancelClassFn: function() {
						var _this = this;
						this.classDialogVisible = false;
					},
					saveClassCodeFn: function() {

						var _this = this;
						var validate = false;
						_this.$refs.refClassForm.validate(function(valid) {
							validate = valid;
						});
						if (!validate) {
							return;
						}
						if (_this.isClassaddFlag) {
							_this.checkSaveCurrClassCode(_this.classFormdata, validate);
						} else {
							let urlparam = 'api/use/plats/paramclass/updateUseParamClass';

							yufp.service.request({
								method: 'POST',
								url: urlparam,
								data: _this.classFormdata,
								callback: function(code, message, response) {

									if (response.code == 0) {
										var paramObject = {};
										paramObject.className = _this.searchFormdata.className;
										paramObject.appCode = _this.nodeTemp.appCode;
										paramObject.dataType = _this.searchFormdata.paramName;

										_this.$refs.refTable.remoteData(paramObject);
										_this.$message('操作成功');
										_this.classDialogVisible = false;
										_this.$refs.refTree.remoteData({});
									} else {
										_this.$message(response.message);
									}
								}
							});
						}

					},

					checkSaveCurrClassCode: function(module, isOk) {
						var _this = this;
						var paramModule = {};
						paramModule.appCode = module.appCode;
						paramModule.classCode = module.classCode;
						yufp.service.request({
							method: 'GET',
							url: "api/use/plats/paramclass/checkParamClassExists",
							data: paramModule,
							async: false,
							callback: function(code, message, response) {
								if (response.code != 0) {
									isOk = false;
									_this.$message(response.message);
								} else {
									if (!response.data) {
										isOk = false;
										_this.$message('该参数代码在系统中已经存在');
									} else {
										let urlparam = "";
										if (_this.isClassaddFlag) {
											urlparam = 'api/use/plats/paramclass/saveUseUseParamClass';
										} else {
											urlparam = 'api/use/plats/paramclass/updateUseParamClass';
										}

										yufp.service.request({
											method: 'POST',
											url: urlparam,
											data: module,
											callback: function(code, message, response) {

												if (response.code == 0) {
													var paramObject = {};
													paramObject.className = _this.searchFormdata.className;
													paramObject.appCode = _this.nodeTemp.appCode;
													paramObject.dataType = _this.searchFormdata.paramName;

													_this.$refs.refTable.remoteData(paramObject);
													_this.$message('操作成功');
													_this.classDialogVisible = false;
													_this.$refs.refTree.remoteData({});
												} else {
													_this.$message({
														message: response.message,
														type: "warning"
													});
												}
											}
										});
									}
								}

							}
						});

					},
					updateTreeFn: function() {
						var _this = this;

						if (!_this.isNodeLeaf) {
							_this.$message("请选择参数分类");
							return;
						}
						if (_this.nodeLeafData.appCode === _this.nodeLeafData.parentId + '_.APPVAR') {
							_this.$message({
								message: "任务参数不允许修改",
								type: "warning"
							});
							return;
						}
						_this.classDialogVisible = true;
						_this.viewClassTitle = _this.viewClassTitleArrry[1];
						_this.isClassaddFlag = false;
						_this.classCodeReadOnly = true;

						_this.isViewFlag = false;
						_this.$nextTick(function() {
							_this.classFormdata.appCode = _this.nodeLeafData.parentId;
							_this.classFormdata.appName = _this.nodeLeafData.parentName;
							_this.classFormdata.classCode = _this.nodeLeafData.appCode.substr(_this.nodeLeafData.parentId.length + 1);
							_this.classFormdata.className = _this.nodeLeafData.appName;
							_this.classFormdata.remark = _this.nodeLeafData.remark;


						});

					},
					deleteTreeFn: function() {
						var _this = this;
						if (!_this.isNodeLeaf) {
							_this.$message("请选择参数分类");
							return;
						}
						if (_this.nodeLeafData.appCode.substr(_this.nodeLeafData.parentId.length + 1) === '.APPVAR') {
							_this.$message({
								message: "任务参数不允许删除",
								type: 'warning'
							});
							return;
						}
						_this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
							confirmButtonText: '确定',
							cancelButtonText: '取消',
							type: 'warning',
							center: true,
							callback: function(action) {
								if (action === 'confirm') {
									let paramObj = {};
									paramObj.appCode = _this.nodeLeafData.parentId;
									paramObj.classCode = _this.nodeLeafData.appCode.substr(_this.nodeLeafData.parentId.length + 1);

									yufp.service.request({
										method: 'DELETE',
										url: "api/use/plats/paramclass/deleteUseParamClass",
										data: paramObj,
										callback: function(code, message, response) {
											if (response.code != 0) {
												_this.$message(response.message);
											} else {
												_this.$message('操作成功');
												var paramObject = {};
												paramObject.className = _this.searchFormdata.appName;
												paramObject.appCode = _this.nodeTemp.appCode;
												_this.$refs.refTree.remoteData({});
												_this.$refs.refTable.remoteData(paramObject);

											}

										}
									});
								}
							}
						});
					},

					/**
					 * 取消
					 */
					cancelFn: function() {
						var _this = this;
						_this.dialogVisible = false;
					},
					/**
					 * 保存
					 */
					saveFn: function() {
						var _this = this;
						var validate = false;
						_this.$refs.refForm.validate(function(valid) {
							validate = valid;
						});
						if (!validate) {
							return;
						}
						var paramObj = _this.$refs.refForm.formdata;
						if (paramObj.paramType === 'C') {
							paramObj.dataSource = "";
							paramObj.sqlexpression = "";
							//在这里判断参数值，小于参数定义的长度
							var len = paramObj.paramSize;
							var val = paramObj.paramValue;
							if (val && val.length > Number(len)) {
								_this.$message("参数值必须小于定义的参数长度！");
								return;
							}
						} else {
							paramObj.paramValue = "";
							//校验sql只能为select 0528去除该项校验
							// if (!_this.validateSql(paramObj.sqlexpression)) {
							// 	_this.$message("只能执行查询sql，请避免DDL/DML语句");
							// 	return
							// }
						}

						let urlparam = "";
						if (_this.addFlag) {
							paramObj.appCode = _this.nodeLeafData.parentId;
							paramObj.classCode = _this.nodeLeafData.appCode.substr(_this.nodeLeafData.parentId.length + 1);
							urlparam = 'api/use/plats/paramValue/saveUseParamValue';
							this.checkSaveParamCode(paramObj, urlparam);
						} else {
							urlparam = 'api/use/plats/paramValue/updateUseParamValue';
							yufp.service.request({
								method: 'POST',
								url: urlparam,
								data: paramObj,
								callback: function(code, message, response) {
									if (response.code == 0) {
										var paramObj = {};

										if (_this.isAppNode) {
											paramObj.appCode = _this.currAppNode.appCode;
										} else if (_this.isNodeLeaf) {
											paramObj.appCode = _this.nodeLeafData.parentId;
											paramObj.classCode = _this.nodeLeafData.appCode.substr(_this.nodeLeafData.parentId.length + 1);
										} else {

										}

										var param = {
											condition: JSON.stringify(paramObj)
										};

										_this.$refs.refTable.remoteData(param);
										_this.$message('操作成功');
										_this.dialogVisible = false;
									} else {
										_this.$message({
											message: response.message,
											type: "warning"
										});
									}
								}
							});
						}
					},
					/**
					 * 控制保存按钮、xdialog、表单的状态
					 * @param viewType 表单类型
					 * @param editable 可编辑,默认false
					 */
					switchStatus: function(viewType, editable) {
						var _this = this;
						_this.viewType = viewType;
						_this.dialogVisible = true;
						_this.formDisabled = !editable;
						_this.saveBtnShow = editable;
						_this.cancelBtnShow = editable;
					},


					paramTypeChangeFn: function(val) {
						const _this = this;
						if (val === 'C' || val === '') {
							_this.sqlQuery = false;
						} else {
							_this.queryDataSourceCode();
							_this.sqlQuery = true;
						}

					},

					/**
					 * 点击树的结点，加载对应的数据
					 */
					nodeClickFn: function(nodeData, node, self) {
						var _this = this;
						var nodeApp = "";
						var classCode = "";


						if (nodeData.nodeType === 'R') {
							_this.showAppName = true;
							_this.showClassName = true;
							_this.isAppNode = false;
							_this.isNodeLeaf = false;
							_this.nodeLeafData = {};
							_this.appNameDisabled = false
							_this.searchFormdata.appName = '';
							_this.classNameDisabled = false;
							_this.searchFormdata.className = '';
							nodeApp = "";
							classCode = "";
						} else if (nodeData.nodeType === 'A') {
							_this.showAppName = false;
							_this.showClassName = true;
							_this.isAppNode = true;
							_this.currAppNode = nodeData;
							_this.isNodeLeaf = false;
							_this.nodeLeafData = {};
							_this.appNameDisabled = true;
							_this.searchFormdata.appName = nodeData.appName;
							_this.classNameDisabled = false;
							_this.searchFormdata.className = '';
							nodeApp = nodeData.appCode;
							classCode = "";
						} else if (nodeData.nodeType === 'C') {
							_this.showAppName = false;
							_this.showClassName = false;
							_this.isAppNode = false;
							_this.isNodeLeaf = true;
							_this.nodeLeafData = nodeData;

							_this.appNameDisabled = true;
							_this.searchFormdata.appName = nodeData.parentName;
							_this.classNameDisabled = true;
							_this.searchFormdata.className = nodeData.appName;
							nodeApp = nodeData.parentId;
							classCode = nodeData.appCode.substr(nodeData.parentId.length + 1);
						}
						//var paramObj = {};
						_this.searchFormdata.appCode = nodeApp;
						_this.searchFormdata.classCode = classCode;

						var param = {
							condition: JSON.stringify(_this.searchFormdata)
						};

						_this.$refs.refTable.remoteData(param);

					},

					testConnect: function() {
						var _this = this;
						var validate = false;
						_this.$refs.refForm.validate(function(valid) {
							validate = valid;
						});
						if (!validate) {
							return;
						}

						var paramObj = {};
						paramObj.classCode = _this.formdata.dataSource;
						if (_this.formdata.appCode != null) {
							paramObj.appCode = _this.formdata.appCode;
						} else {
							paramObj.appCode = _this.nodeLeafData.parentId;
						}

						paramObj.testSql = _this.formdata.sqlexpression;

						//校验sql只能为select 0528去除该项校验
						// if (!_this.validateSql(paramObj.testSql)) {
						// 	_this.$message("只能执行查询sql，请避免DDL/DML语句");
						// 	return
						// }
						_this.exportLoading = true;
						yufp.service.request({
							method: 'POST',
							url: "api/use/plats/rdbcfg/getConnTestBySQL",
							data: paramObj,
							callback: function(code, message, response) {
								_this.exportLoading = false;
								if (response.code != 0) {
									_this.$message("连接失败，请检查参数");
								} else {
									if (response.data == true) {
										_this.$message('SQL执行成功');
									} else {
										_this.$message({
											message: "连接失败,请检查数据源配置以及确保SQL语句只返回一个值",
											type: "error"
										});
									}
								}
							}
						});
					},
					/**
					 * 新增
					 */
					addFn: function() {
						var _this = this;
						// _this.isReadOnly = false;
						_this.dialogVisible = true;
						_this.isViewFlag = false;
						_this.sqlQuery = false;
						_this.viewTitle = _this.viewTitleArrry[0];
						_this.addFlag = true;
						_this.isReadOnly = false;
						//_this.$set(_this.databaseServerAllField[0].fields[0], 'readonly',  _this.isReadOnly );
						_this.$nextTick(function() {

							_this.$refs.refForm.resetFields();
							_this.formdata.sqlexpression = '';
							_this.formdata.appName = _this.nodeLeafData.parentName;
							_this.formdata.className = _this.nodeLeafData.appName;
							_this.formdata.paramType = "C";

						});
					},

					viewDataFn: function(data) {
						var _this = this;
						_this.isViewFlag = true;
						_this.sqlQuery = false;
						_this.isReadOnly = true;
						_this.viewTitle = _this.viewTitleArrry[2];
						_this.dialogVisible = true;
						_this.addFlag = false;

						var val = data.paramType;
						if (val === 'C' || val === '') {
							_this.sqlQuery = false;
						} else {
							_this.queryDataSourceCode();
							_this.sqlQuery = true;
						}

						_this.$nextTick(function() {

							//_this.$refs.refForm.resetFields();
							_this.formdata.sqlexpression = '';
							var paramObj = {};
							paramObj.appCode = data.appCode;

							yufp.service.request({
								method: 'GET',
								url: "api/use/plats/rdbcfg/queryList",
								data: paramObj,
								async: false,
								callback: function(code, message, response) {
									if (response.code != 0) {
										isOk = false;
										_this.$message(response.message);
									} else {
										_this.dataSources.splice(0);
										_this.dataSources.push({
											key: "USEDB",
											value: "USE内部数据库"
										});
										for (let i = 0; i < response.data.length; i++) {
											_this.dataSources.push({
												key: response.data[i].classCode,
												value: response.data[i].className
											});
										}
										_this.formdata.appName = data.appName;
										_this.formdata.appCode = data.appCode;
										_this.formdata.classCode = data.classCode;
										_this.formdata.className = data.className;
										_this.formdata.paramCode = data.paramCode;
										_this.formdata.paramName = data.paramName;
										_this.formdata.paramType = data.paramType;
										_this.formdata.paramSize = data.paramSize;
										_this.formdata.paramValue = data.paramValue;
										_this.formdata.dataSource = data.dataSource;
										_this.formdata.sqlexpression = data.sqlexpression;
										_this.formdata.remark = data.remark;
									}

								}
							});
						});
					},

					/**
					 * 修改
					 */
					modifyFn: function() {
						var _this = this;

						if (_this.$refs.refTable.selections.length != 1) {
							_this.$message({
								message: '请选择一条记录进行操作',
								type: 'warning'
							});
							return;
						}
						_this.isViewFlag = false;
						_this.sqlQuery = false;
						_this.isReadOnly = true;
						_this.viewTitle = _this.viewTitleArrry[1];
						_this.dialogVisible = true;
						_this.addFlag = false;
						var val = _this.$refs.refTable.selections[0].paramType;
						if (val === 'C' || val === '') {
							_this.sqlQuery = false;
						} else {
							_this.queryDataSourceCode();
							_this.sqlQuery = true;
						}

						_this.$nextTick(function() {

							_this.$refs.refForm.resetFields();
							_this.formdata.sqlexpression = '';
							var paramObj = {};
							paramObj.appCode = _this.$refs.refTable.selections[0].appCode;

							yufp.service.request({
								method: 'GET',
								url: "api/use/plats/rdbcfg/queryList",
								data: paramObj,
								async: false,
								callback: function(code, message, response) {
									if (response.code != 0) {
										isOk = false;
										_this.$message(response.message);
									} else {
										_this.dataSources.splice(0);
										for (let i = 0; i < response.data.length; i++) {
											_this.dataSources.push({
												key: response.data[i].classCode,
												value: response.data[i].className
											});
										}
										_this.formdata.appName = _this.$refs.refTable.selections[0].appName;
										_this.formdata.appCode = _this.$refs.refTable.selections[0].appCode;
										_this.formdata.classCode = _this.$refs.refTable.selections[0].classCode;
										_this.formdata.className = _this.$refs.refTable.selections[0].className;
										_this.formdata.paramCode = _this.$refs.refTable.selections[0].paramCode;
										_this.formdata.paramName = _this.$refs.refTable.selections[0].paramName;
										_this.formdata.paramType = _this.$refs.refTable.selections[0].paramType;
										_this.formdata.paramSize = _this.$refs.refTable.selections[0].paramSize;
										_this.formdata.paramValue = _this.$refs.refTable.selections[0].paramValue;
										_this.formdata.dataSource = _this.$refs.refTable.selections[0].dataSource;
										_this.formdata.sqlexpression = _this.$refs.refTable.selections[0].sqlexpression;
										_this.formdata.remark = _this.$refs.refTable.selections[0].remark;
									}

								}
							});
						});
					},
					/**
					 * 删除
					 */
					deleteFn: function() {
						var _this = this;
						var selections = _this.$refs.refTable.selections;
						if (selections.length != 1) {
							_this.$message({
								message: '请选择一条记录进行操作',
								type: 'warning'
							});
							return;
						}

						_this.$confirm('此操作将永久删除该记录且会影响所配置作业, 是否继续?', '警告', {
							confirmButtonText: '确定',
							cancelButtonText: '取消',
							type: 'warning',
							center: true,
							callback: function(action) {
								if (action === 'confirm') {
									yufp.service.request({
										method: 'DELETE',
										url: "api/use/plats/paramValue/deleteUseParamValue",
										data: selections[0],
										callback: function(code, message, response) {
											if (response.code != 0) {
												isOk = false;
												_this.$message(response.message);
											} else {
												_this.$message('操作成功');
												var paramObj = {};

												if (_this.isAppNode) {
													paramObj.appCode = _this.currAppNode.appCode;
												} else if (_this.isNodeLeaf) {
													paramObj.appCode = _this.nodeLeafData.parentId;
													paramObj.classCode = _this.nodeLeafData.appCode.substr(_this.nodeLeafData.parentId.length + 1);
												} else {

												}

												var param = {
													condition: JSON.stringify(paramObj)
												};

												_this.$refs.refTable.remoteData(param);

											}

										}
									});
								}
							}
						});
					},
					checkSaveParamCode: function(paramObj, url) {

						var _this = this;
						if (!_this.addFlag) {
							return;
						}

						var tmpCurrentObject = {};
						tmpCurrentObject.classCode = paramObj.classCode;
						tmpCurrentObject.paramCode = paramObj.paramCode;
						tmpCurrentObject.appCode = paramObj.appCode;


						yufp.service.request({
							method: 'GET',
							url: "api/use/plats/paramValue/checkParamValueExists",
							data: tmpCurrentObject,
							async: false,
							callback: function(code, message, response) {
								if (response.code != 0) {
									isOk = false;
									_this.$message(response.message);
								} else {
									if (!response.data) {
										isOk = false;
										_this.$message({
											message: '该参数代码在系统中已经存在',
											type: 'warning'
										});
									} else {

										yufp.service.request({
											method: 'POST',
											url: url,
											data: paramObj,
											callback: function(code, message, response) {
												if (response.code == 0) {
													var paramObj = {};

													if (_this.isAppNode) {
														paramObj.appCode = _this.currAppNode.appCode;
													} else if (_this.isNodeLeaf) {
														paramObj.appCode = _this.nodeLeafData.parentId;
														paramObj.classCode = _this.nodeLeafData.appCode.substr(_this.nodeLeafData.parentId.length + 1);
													} else {

													}

													var param = {
														condition: JSON.stringify(paramObj)
													};

													_this.$refs.refTable.remoteData(param);
													_this.$message('操作成功');
													_this.dialogVisible = false;
												} else {
													_this.$message(response.message);
												}
											}
										});

									}
								}

							}
						});
					},

					queryDataSourceCode: function() {
						var _this = this;
						var paramObj = {};
						paramObj.appCode = this.nodeLeafData.parentId;

						yufp.service.request({
							method: 'GET',
							url: "api/use/plats/rdbcfg/queryList",
							data: paramObj,
							async: false,
							callback: function(code, message, response) {
								if (response.code != 0) {
									isOk = false;
									_this.$message(response.message);
								} else {
									_this.dataSources.splice(0);
									//_this.dataSources.push({ key: "USEDB", value: "USE内部数据库" });
									for (let i = 0; i < response.data.length; i++) {
										_this.dataSources.push({
											key: response.data[i].classCode,
											value: response.data[i].className
										});
									}
								}

							}
						});
					}
				},

			});
		};
	});
